import { createApp } from 'vue';
import 'amfe-flexible/index.js';
import './assets/iconfont/iconfont.js';
import ElementPlus from 'element-plus';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'element-plus/dist/index.css';
import './style/global.scss';
import './style/common.scss';
import directives from './directives/index';
import router from './router';
import store from './store';
import App from './App.vue';
import { remConfig } from '@/utils/index';
import common from '@/utils/common';
import PDFTool from '@/utils/pdfjs';

const app = createApp(App);
// 全局挂载element-plus中icon图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
// 全局挂载通用工具函数
for (const [key, fn] of Object.entries(common)) {
    app.config.globalProperties[key] = fn;
}

// 创建全局生成pdf线程路径
PDFTool.setGlobalWorkerSrc();

app.config.globalProperties.$BASE_IMG_URL = import.meta.env.VITE_IMG_BASE_URL;
app.config.globalProperties.$VITE_STATIC_URL = import.meta.env.VITE_STATIC_URL;
app.use(router);
app.use(store);
app.use(ElementPlus);
directives(app);
remConfig.remConfig();
app.mount('#app');

// 声明全局变量属性
declare module 'vue' {
    export interface ComponentCustomProperties {
        $BASE_IMG_URL: string;
        /** 静态资源图片地址前缀 */
        $VITE_STATIC_URL: string;
        /** 下载自定义指令 */
        vDownload: string | undefined;
        /** 失去焦点时去掉前后空格 */
        vTrim: undefined;
        /** 全局处理图片路径方法 */
        handlerImgSrc: (src?: string) => undefined | string;
        /** 全局打开询盘云方法 */
        openConsultDialog: () => void;
        /** 全局时间格式化函数 */
        formatDate: (date: number | Date, formatStr?: string) => string;
        /** 切换语言选择图片 */
        changeLanguageImg: (imgList: Array<string>) => string;
        /** 打开新页签 */
        open: (
            path: string | { path: string; query: Record<string, any> },
            type?: 'front' | 'backend',
        ) => void;
        /** 转换千分位 */
        thousands: (num: number) => string;
    }
}
